package controller.v2;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import model.AdVO;
import model.BoardVO;
import model.GoodVO;
import model.MemberVO;
import service.v2.AdService;
import service.v2.BoardService;
import service.v2.ConfigService;
import service.v2.GoodService;
import service.v2.MemberService;
import util.PropertieUtil;

@Controller
@RequestMapping("/v2/page")
public class AppPageController {
	@Autowired
	private BoardService boardService;	
	@Autowired
	private GoodService goodService;	
	@Autowired
	private AdService adService;	
	@Autowired
	private ConfigService configService;
	@Autowired
	private MemberService memberService;
	
	/*公告详细*/
	@RequestMapping("/noticeDetail")
	public String borderDetail(@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,String board_id,HttpServletRequest request,
			HttpServletResponse response,BoardVO boardVO,MemberVO memberVO)throws Exception{
		if(os != null){
			os = os.toLowerCase();
		}
		if(member_id !=null){
			memberVO = memberService.getAllInfoById(member_id);
			request.setAttribute("memberLevel",memberVO.getLevel());
		}
		BoardVO boardDetail = boardService.getDetailById(board_id);
		request.setAttribute("boardDetail",boardDetail);
		request.setAttribute("os",os);
		
		return"/app/page/boardDetail";
	}

	/*低佣金使用帮助*/
	@RequestMapping("/buyCashHelp")
	public String buyCashHelp(String board_id,HttpServletRequest request,HttpServletResponse response,BoardVO boardVO)throws Exception{
		String buyCashHelpId = PropertieUtil.loadPropertie("buy_cash_help");
		BoardVO buyCashHelp = boardService.getBuyCashHelpById(buyCashHelpId);
		request.setAttribute("buyCashHelp", buyCashHelp);
		
		return "/app/page/buyCashHelp";
	}
	
	/*商品详细*/	
	@RequestMapping("/goodDetail")
	public String goodDetail(String good_id,HttpServletRequest request,HttpServletResponse response,GoodVO goodVO)throws Exception{
		GoodVO goodDetail = goodService.getGoodDetilById(good_id);
		request.setAttribute("goodDetail", goodDetail);

		return "/app/page/goodDetail";
	} 

	/*广告空页面*/
	@RequestMapping("/adPage")
	public String adPage(@RequestHeader (value="OS", required=false) String os,@RequestHeader (value="AUTHORIZATION", required=false) String token,@RequestHeader (value="SECRET", required=false)  String member_id,
			HttpServletRequest request,HttpServletResponse response, String ad_id,AdVO adVO,MemberVO memberVO)throws Exception{
		if(os != null){
			os = os.toLowerCase();
		}
		if(member_id !=null){
			memberVO = memberService.getAllInfoById(member_id);
			request.setAttribute("memberLevel",memberVO.getLevel());
		}
		AdVO adVo_info = adService.getContentById(ad_id);
		request.setAttribute("adVo_info",adVo_info);
		
		return "/app/page/adPage";
	}
	/*友米乐用户注册协议*/
	@RequestMapping("/registerProtocol")
	public String registerProtocol(String board_id,HttpServletRequest request,HttpServletResponse response,BoardVO boardVO)throws Exception{
		String register_protocol = PropertieUtil.loadPropertie("register_protocol");
		BoardVO buyregister_text = boardService.getBuyCashHelpById(register_protocol);
		request.setAttribute("buyregister_text", buyregister_text);

		return "/app/page/registerProtocol";
	}
	/*首页小图成为会员网页*/
	@RequestMapping("/unimember")
	public String unimember(@RequestHeader (value="OS", required=false) String os,HttpServletRequest request,HttpServletResponse response)throws Exception{
		if(os != null){
			os = os.toLowerCase();
		}
		String host = configService.loadConfig("HOST");

		request.setAttribute("os",os);
		request.setAttribute("host_url",host);
		request.setAttribute("wechat_host",configService.loadConfig("WECHAT_HOST"));
		return "/app/page/unimember";
	}
	/*首页小图成为会员网页->银卡会员*/
	@RequestMapping("/yinka")
	public String yinka(@RequestHeader (value="OS", required=false) String os,HttpServletRequest request,HttpServletResponse response)throws Exception{
		String host = configService.loadConfig("HOST");
		
		request.setAttribute("host_url",host);
		request.setAttribute("wechat_host",configService.loadConfig("WECHAT_HOST"));
		return "/app/page/yinka";
	}
	/*首页小图成为会员网页->金卡*/
	@RequestMapping("/jinka")
	public String jinka(@RequestHeader (value="OS", required=false) String os,HttpServletRequest request,HttpServletResponse response)throws Exception{
		String host = configService.loadConfig("HOST");
		
		request.setAttribute("host_url",host);
		request.setAttribute("wechat_host",configService.loadConfig("WECHAT_HOST"));
		return "/app/page/jinka";
	}
	/*首页小图成为会员网页->铂金*/
	@RequestMapping("/bojin")
	public String bojin(@RequestHeader (value="OS", required=false) String os,HttpServletRequest request,HttpServletResponse response)throws Exception{
		String host = configService.loadConfig("HOST");

		request.setAttribute("host_url",host);
		request.setAttribute("wechat_host",configService.loadConfig("WECHAT_HOST"));
		return "/app/page/bojin";
	}
	/*首页小图成为会员网页->钻石*/
	@RequestMapping("/zuanshi")
	public String zuanshi(@RequestHeader (value="OS", required=false) String os,HttpServletRequest request,HttpServletResponse response)throws Exception{
		String host = configService.loadConfig("HOST");

		request.setAttribute("host_url",host);
		request.setAttribute("wechat_host",configService.loadConfig("WECHAT_HOST"));
		return "/app/page/zuanshi";
	}
}
